/*=========================================================================
The Impact of Denying a Wanted Abortion on Women and Children
Authors: Juliana Londoño-Vélez and Estefanía Saravia

Creation date: January 9th, 2024
--------------------------------------------------------------------------
Table 3 - Testing Balance
=========================================================================*/

use "$data/Final_Medellin_SisbenIII.dta", replace


keep if Caso_Aborto ==1

	
global outcomes Edad_Encuesta Edad_Tutela Embarazo_adolescente  Nivel_0 Primaria Secundaria Media Superior puntaje_float Estrato_0_1 thogar Numero_Hijos Any_Children Soltera Casada Separada Viuda Cabecera


mat a=J(21,7,.)

matrix rownames a =  $outcomes "F-stat" "p-value" "N"



local i=1
foreach var in $outcomes {
	sum `var' if Niega==0
	mat a[`i',1]=`r(mean)' 

	reghdfe `var' Niega, abs(oficina#time) cluster(id_juez)
	mat a[`i',2]=_b[Niega]
	mat a[`i',3]=_se[Niega]
	

	
	reghdfe `var' Mujer_Ponente, abs(oficina#time) cluster(id_juez)
	mat a[`i',4]=_b[Mujer_Ponente]
	mat a[`i',5]=_se[Mujer_Ponente]

	reghdfe `var' judge_stringency, abs(oficina#time) cluster(id_juez)
	mat a[`i',6]=_b[judge_stringency]
	mat a[`i',7]=_se[judge_stringency]
	
	local i=`i'+1
	}



reghdfe Niega $outcomes, abs(oficina#time) cluster(id_juez)
testparm $outcomes

mat a[19,2]=r(F)
mat a[20,2]=r(p)

mat a[21,2]=e(N)



reghdfe Mujer_Ponente $outcomes, abs(oficina#time) cluster(id_juez)
testparm $outcomes

mat a[19,4]=r(F)
mat a[20,4]=r(p)

mat a[21,4]=e(N)

reghdfe judge_stringency $outcomes, abs(oficina#time) cluster(id_juez)
testparm $outcomes

mat a[19,6]=r(F)
mat a[20,6]=r(p)

mat a[21,6]=e(N)


	svmat2 a, rnames(outcome)
	
	drop if outcome==""
	
	rename a1 mean
	rename a2 coef_denied
	rename a3 se_denied
	rename a4 coef_woman
	rename a5 se_woman
	rename a6 coef_stringency
	rename a7 coef_se

	
	
	keep outcome mean coef_denied se_denied coef_woman se_woman coef_stringency coef_se
	
	order outcome mean coef_denied se_denied coef_woman se_woman coef_stringency coef_se
	
	export excel using "$output/Tables paper matrices replication.xlsx", sheet("Table 3", modify) 	
	
